<template>
    <el-dialog class='dialog-box' title="批量通过" :visible.sync="batchThroughData.dialogState" size="tiny"  @close="close('dataForm')" @open='open'>
        <el-form v-loading='loading' class="form-content"  :model="dataForm"  ref="dataForm" label-width="80px"  label-position='left'>
            <el-row>
                <el-col :span="24">
                    <el-form-item label="总计数量" >
                        <span>{{dataForm.num}}笔</span>
                    </el-form-item>
                </el-col>
            </el-row>
            <el-row>
                <el-col :span="24">
                    <el-form-item label="总计金额">
                        <span>{{dataForm.money}}元</span>
                    </el-form-item>
                </el-col>
            </el-row>
            <el-row>
                <el-col :span="24">
                    <el-form-item label-width="0px">
                        <span><font color="red">* </font> 请在核对后点击确认。</span>
                    </el-form-item>
                </el-col>
            </el-row>
        </el-form>

        <div slot="footer" class="dialog-footer">
            <el-button @click="resetForm('dataForm')"> 取 消 </el-button>
            <el-button type="primary" @click="submitForm('dataForm')"> 确 定 </el-button>
        </div>
    </el-dialog>
</template>

<script>
    import { getAuditByAll } from 'api/integralManage';
    export default {
        props: {
            batchThroughData: {
                default() {
                    return {
                        dialogState: false,
                        multipleSelection: ''
                    }
                },
                required: true
            }
        },
        data() {
            return {
                loading: false,
                dataForm: {
                    num: '',
                    money: null
                },
                idList: []
            }
        },
        computed: {
           
        },
        methods: {
            open() {
                this.dataForm.num = this.batchThroughData.multipleSelection.length;
                this.batchThroughData.multipleSelection.forEach(function(element) {
                    this.dataForm.money +=Number(element.withdrawalCash);
                    this.idList.push(element.id);
                }, this);
            },
            submitForm(dataForm) {
                this.$refs[dataForm].validate((valid) => {
                    if (valid) {

                        let status = '1';  // “1:通过  2：完成”,
                        let id = this.idList.join(','); // id拼接 “,”隔开” 
                        this.loading = true;  
                        getAuditByAll(status, id).then(response => {
                            this.loading = false;
                            if (response.data.status == 200) {
                                this.$message.success(response.data.errorMsg);
                                this.batchThroughData.dialogState = false;
                                this.$emit('search');
                            } else {
                                this.$message.error(response.data.errorMsg);
                            }
                        }).catch(() => {
                            this.loading = false;
                        })
                    }
                })
            },
            resetForm(dataForm) {
                this.dataForm.money = 0;
                this.batchThroughData.dialogState = false;
                this.$refs[dataForm].resetFields();
            },
            close(dataForm) {
                this.dataForm.money = 0;
                this.batchThroughData.dialogState = false;
                this.$refs[dataForm].resetFields();
            }
        }
    }

</script>

<style lang="scss" scoped>
    .dialog-box{
        .form-content{
            width: 80%;
            margin: 0 auto; 
        }
        .dialog-footer{
            width: 80%;
            margin: 0 auto; 
            text-align:center;
        }
    }
</style>